package com.turing.data.scripts.contract.filter

import com.turing.common.util.FileUtils
import com.turing.common.util.StringUtils
import com.turing.data.engine.CombineLongText
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

/**
 * 场景：资产管理合同
 * 版本：Version 1
 * 要素名称：是否使用摊余成本法
 */

class IfAmortizedCostMethod_30198_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        def Regex_HAS = /.*摊余成本.*/

        def textPathMap = dependParams.textPathMap

        List<TaskElementVO.DrawResultVO > trueValueSet = new ArrayList<>()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        if (resultVOs!=null && resultVOs.size()>0) {
            for (int i = 0; i < resultVOs.size(); i++) {
                if(StringUtils.isEmpty(resultVOs.get(i).childTaskSn)){
//                    return  resultVOs
                    continue
                }
                def rawPath = textPathMap.get(resultVOs.get(i).childTaskSn)
                def rawText = FileUtils.loadJson(rawPath)
                String trueValue = CombineLongText.fetchNearbyText(resultVOs.get(i), rawText,20)

                if (trueValue =~ Regex_HAS  ){
                    trueValueSet.add(resultVOs.get(i))
                    return trueValueSet
                }
            }
        }

        //默认
//        if(trueValueSet.size() == 0){
            TaskElementVO.DrawResultVO defaultDrawResultVO = new TaskElementVO.DrawResultVO()
            defaultDrawResultVO.text = "否"
            trueValueSet.add(defaultDrawResultVO)
            return trueValueSet
//        }

    }

}
